package com.example.yls.demob;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditStuActivity extends AppCompatActivity {
    private EditText editname;
    private EditText editstuno;
    private EditText editage;
    private Button addstu;
    private static final String TAG = "EditStuActivity";
 /*   private String name;
    private int age;
    private String stuno;*/
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_stu);


        initBundler();
        sendData();



    }
    private void initBundler() {

        editage=findViewById(R.id.edit_age1);
        editname=findViewById(R.id.edit_name1);
        editstuno=findViewById(R.id.edit_stuno1);
        addstu=findViewById(R.id.btn_editstu);
        Intent intent=getIntent();
        String stuno=intent.getStringExtra("STUNO");
        String name=intent.getStringExtra("NAME");
        int age=intent.getIntExtra("AGE",0);
        editname.setText(name);
        editage.setText(String.valueOf(age));
        editstuno.setText(stuno);


    }

    private void sendData() {
        addstu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    Intent intent=new Intent();
                    String stuno=editstuno.getText().toString();
                    String name=editname.getText().toString();
                    int age=Integer.valueOf(editage.getText().toString());
                    intent.putExtra("STUNO",stuno);
                    intent.putExtra("AGE",age);
                    intent.putExtra("NAME",name);
                    setResult(3001,intent);
                    finish();
            }
        });


    }




}
